"""
AST(抽象语法树节点) abstract syntax tree
"""

class Node(object):
    pass


class NumberNode(Node):
    # 数字节点
    def __init__(self, token):
        self.token = token
        self.pos_start = self.token.pos_start
        self.pos_end = self.token.pos_end

    def __repr__(self):
        return f'{self.token}'


class BinOpNode(Node):
    # 二元操作节点 + - * / , 1 + 2 ==> left_node = NumberNode(1), right_node = NumberNode(2), token = +
    def __init__(self, left_node, op_token, right_node):
        """
        :param left_node: 左节点
        :param op_token: 操作符
        :param right_node: 右节点
        """
        self.op_token = op_token
        self.left_node = left_node
        self.right_node = right_node
        self.pos_start = self.op_token.pos_start
        self.pos_end = self.op_token.pos_end

    def __repr__(self):
        return f'({self.left_node}, {self.op_token}, {self.right_node})'


class UnaryOpNode(Node):

    # 一元操作, 如负数
    def __init__(self, op_token, node):
        """
        :param op_token: 正号或符号
        :param node: 右节点
        """
        self.op_token = op_token
        self.node = node
        self.pos_start = self.op_token.pos_start
        self.pos_end = self.op_token.pos_end

    def __repr__(self):
        return f'({self.op_token}, {self.node})'